package com.example.demo.dao;

import com.example.demo.entity.CodeView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CodeDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public int saveCode(CodeView code) {
        return jdbcTemplate.update("insert into  code(time,code) values (?,?)",
                code.getTime(), code.getCode());
    }

    public List<CodeView> queryCode(CodeView code) {
        return jdbcTemplate.query("select * from code where time = ?",
                new BeanPropertyRowMapper<>(CodeView.class), code.getTime());
    }


    public List<CodeView> queryList() {
        return jdbcTemplate.query("select * from code where 1=1 limit 500",
                new BeanPropertyRowMapper<>(CodeView.class));
    }

}
